package com.leetcode.LC;

public class LC463 {
    public int islandPerimeter(int[][] grid) {

        int max = 0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if (grid[i][j] == 1) {
                    if (i==0||grid[i-1][j]==0) max += 1;//顶部
                    if (i==grid.length-1||grid[i+1][j]==0) max += 1;//底部
                    if (j==0||grid[i][j-1]==0) max += 1;//左侧
                    if (j==grid[0].length-1||grid[i][j+1]==0) max += 1;//右侧
                }
            }
        }
        return max;
    }
}
